﻿/**
 * ...
 * @author waneck
 */

package asc.io;
import asc.io.File;

class FileInput extends haxe.io.Input
{
	var file:FileHandle;
	
	public function new(file) 
	{
		this.file = file;
	}
	
	override public function readByte() : Int
	{
		var r = file.readByte();
		if (r == -1)
			throw new haxe.io.Eof();
		else
			return r;
	}
	
	override public function readLine():String
	{
		return file.readln();
	}
	
	override public function close()
	{
		file.close();
	}
	
	public function seek(p:Int, pos:FileSeek)
	{
		var finalpos =
		switch(pos)
		{
			case SeekBegin:
				-file.position + p;
			case SeekCur:
				p;
			case SeekEnd:
				(file.length - file.position) + p;
		}
		
		file.seek(finalpos);
	}
	
	public function tell():Int
	{
		return file.position;
	}
	
	public function eof():Bool
	{
		return file.eof();
	}
}